from .registry import BACKBONES, HEADS, LOSSES, RECOGNIZERS
from utils import build

def build_backbone(cfg):
    """Build backbone."""
    return build(cfg, BACKBONES)


def build_head(cfg):
    """Build head."""
    return build(cfg, HEADS)


def build_loss(cfg):
    """Build loss."""
    return build(cfg, LOSSES)


def build_recognizer(cfg):
    """Build recognizer."""
    return build(cfg, RECOGNIZERS, key='framework')


def build_model(cfg):
    cfg_copy = cfg.copy()
    framework_type = cfg_copy.get('framework')
    # build framework , which contains model's backbone and head
    if framework_type in RECOGNIZERS:
        return build_recognizer(cfg)
    # elif framework_type in XX:
    else:
        raise NotImplementedError
